class BlackDeathPawn extends GamePawn
	abstract;

//Weapon Animation
var AnimNodeSequence HAttackAnim;
var AnimNodeSequence VAttackAnim;
var AnimNodeSequence EquipAnim;
var AnimNodeBlendPerBone SwingBlend;
var AnimNodeBlendBySpeed IdleBlend;
var AnimNodeBlendPerBone ZombieAttack;
var AnimNodeSequence ZombieSlash;
var AnimNodeBlend SwingVar;
var AnimNodeBlendList WeaponBlend;
var AnimNodeBlendList HealthState;

//The socket that weapons attach to
var name WeaponSocket;

//Wiether or not pawn is currently invisible
var bool isHidden;

/** The pawn's light environment */
var DynamicLightEnvironmentComponent LightEnvironment;

var bool bOnFire;
//How much damage being lit of fire does per second
var int FireDamage;
var Name fireSocket;
var ParticleSystemComponent FireParticleEffectComponent;

/** Initial inventory */
var() array< class<Inventory> >	InitialInventory;


//URGENT: CHANGE THE VISIBILTY MODIFY TO USE THE DEFULT BLACKDEATH WEAPON CLASS WHEN IT EXISTS!!!!!
//END VARIBLES


simulated function PostBeginPlay()
{
	super.PostBeginPlay();
	isHidden = false;
	bOnFire = false;
	SetMovementPhysics();
}

/*This Function is called after the AnimTre is initialized.
*Any nodes that we want to control code, we should look up here.
*/
	simulated event PostInitAnimTree(SkeletalMeshComponent SkelComp)
	{
		//`log("postinit anim tree");
		super.PostInitAnimTree(SkelComp);
		if (SkelComp == Mesh)
		{
			IdleBlend = AnimNodeBlendBySpeed(Mesh.FindAnimNode('blendBySpeedNode'));
			SwingBlend = AnimNodeBlendPerBone(Mesh.FindAnimNode('SwingBlend'));
			HAttackAnim = AnimNodeSequence(Mesh.FindAnimNode('Horizontal'));
			VAttackAnim = AnimNodeSequence(Mesh.FindAnimNode('Vertical'));
			SwingVar = AnimNodeBlend(Mesh.FindAnimNode('SwingVar'));
			ZombieAttack = AnimNodeBlendPerBone(Mesh.FindAnimNode('ZombieAttack'));
			ZombieSlash = AnimNodeSequence(Mesh.FindAnimNode('zombieslash'));
			EquipAnim = AnimNodeSequence(Mesh.FindAnimNode('equip'));
			WeaponBlend = AnimNodeBlendList(Mesh.FindAnimNode('WeaponBlend'));
			HealthState = AnimNodeBlendList(Mesh.FindAnimNode('HealthState'));
			
			//`log("Attackanim"@IdleBlend);
		}
	}
	
	simulated function LightSwing()
	{
		SwingBlend.SetBlendTarget(1.0,0.0);
		SwingVar.SetBlendTarget(0.0,0.0);
		HAttackAnim.PlayAnim(false,1.0,0.0);
	}
	
	simulated function HeavySwing()
	{
		SwingBlend.SetBlendTarget(1.0,0.0);
		SwingVar.SetBlendTarget(1.0,0.0);
		VAttackAnim.PlayAnim(false,1.0,0.0);
	}
	
	simulated function EndSwing()
	{
		SwingBlend.SetBlendTarget(0.0,0.3);
	}


function AddDefaultInventory()
{
	local int i;
	for (i=0; i < InitialInventory.Length; i++)
	{
		CreateInventory(InitialInventory[i]);
	}
	Controller.SwitchToBestWeapon(false);
}


simulated function ChangeVisibility(bool bIsVisible)
{
	if (Mesh != None)
	{
		mesh.SetHidden(!bIsVisible);
	}
	if(BlackDeathInventoryManager(InvManager) != none)
	{
		BlackDeathInventoryManager(InvManager).SetItemsHidden(bIsVisible);
	}
}

//Tell the game to use the third person camera always
simulated function name GetDefaultCameraMode(PlayerController RequestedBy)
{
	return 'FollowCam';
	//return 'ThirdPerson';
}

simulated function Ignite()
{
	if(!bOnFire)
	{
		Mesh.AttachComponentToSocket(FireParticleEffectComponent, fireSocket);
		`log("igniteing");
		SetTimer(1.0, true, 'DealFireDamage');
		bOnFire = true;
	}
}

simulated function Extinguish()
{
	if(bOnFire)
	{
		Mesh.DetachComponent(FireParticleEffectComponent);
		ClearTimer('DealFireDamage');
		bOnFire = false;
	}
}

simulated function DealFireDamage()
{
	TakeDamage(FireDamage, None, Location, vect(0,0,0), class'DmgType_Crushed');
	`log("Enemy Health now"@Health);
}

simulated function PlayDying(class<DamageType> DamageType, vector HitLoc)
{
  local vector ApplyImpulse, ShotDir;
  
  bReplicateMovement = false;
  bTearOff = true;
  Velocity += TearOffMomentum;
  SetDyingPhysics();
  bPlayedDeath = true;
  HitDamageType = DamageType; // these are replicated to other clients
  TakeHitLocation = HitLoc;
  if ( WorldInfo.NetMode == NM_DedicatedServer )
  {
    GotoState('Dying');
    return;
  }
  InitRagdoll();
  mesh.MinDistFactorForKinematicUpdate = 0.f;
  
  if (Physics == PHYS_RigidBody)
  {
    //@note: Falling instead of None so Velocity/Acceleration don't get cleared
    setPhysics(PHYS_Falling);
  }
  PreRagdollCollisionComponent = CollisionComponent;
  CollisionComponent = Mesh;
  if( Mesh.bNotUpdatingKinematicDueToDistance )
  {
    Mesh.ForceSkelUpdate();
    Mesh.UpdateRBBonesFromSpaceBases(TRUE, TRUE);
  }
  if( Mesh.PhysicsAssetInstance != None )
    Mesh.PhysicsAssetInstance.SetAllBodiesFixed(FALSE);
  Mesh.SetRBChannel(RBCC_Pawn);
  Mesh.SetRBCollidesWithChannel(RBCC_Default,TRUE);
  Mesh.SetRBCollidesWithChannel(RBCC_Pawn,TRUE);
  Mesh.SetRBCollidesWithChannel(RBCC_Vehicle,TRUE);
  Mesh.SetRBCollidesWithChannel(RBCC_Untitled3,FALSE);
  Mesh.SetRBCollidesWithChannel(RBCC_BlockingVolume,TRUE);
  Mesh.ForceSkelUpdate();
  Mesh.UpdateRBBonesFromSpaceBases(TRUE, TRUE);
  Mesh.PhysicsWeight = 1.0;
  Mesh.bUpdateKinematicBonesFromAnimation=false;
  // mesh.bPauseAnims=True;
  Mesh.SetRBLinearVelocity(Velocity, false);
  mesh.SetTranslation(vect(0,0,1) * 6);
  Mesh.ScriptRigidBodyCollisionThreshold = MaxFallSpeed;
  Mesh.SetNotifyRigidBodyCollision(true);
  Mesh.WakeRigidBody();
  if( TearOffMomentum != vect(0,0,0) )
  {
    ShotDir = normal(TearOffMomentum);
    ApplyImpulse = ShotDir * DamageType.default.KDamageImpulse;
    // If not moving downwards - give extra upward kick
    if ( Velocity.Z > -10 )
    {
      ApplyImpulse += Vect(0,0,1)*2;
    }
    Mesh.AddImpulse(ApplyImpulse, TakeHitLocation,, true);
  }
  GotoState('Dying');
}

DefaultProperties
{
	InventoryManagerClass=class'BlackDeathInventoryManager'
	ControllerClass=class'BlackDeathEnemyController'
	Components.Remove(Sprite)
//Setting up the light environment
    Begin Object Class=DynamicLightEnvironmentComponent Name=MyLightEnvironment
        ModShadowFadeoutTime=0.25
        MinTimeBetweenFullUpdates=0.2
        AmbientGlow=(R=.01,G=.01,B=.01,A=1)
        AmbientShadowColor=(R=0.15,G=0.15,B=0.15)
        LightShadowMode=LightShadow_ModulateBetter
  		ShadowFilterQuality=SFQ_High
        bSynthesizeSHLight=TRUE
    End Object
    Components.Add(MyLightEnvironment)
	LightEnvironment=MyLightEnvironment
//Setting up the mesh and animset components
    Begin Object Class=SkeletalMeshComponent Name=InitialSkeletalMesh
        CastShadow=true
        bCastDynamicShadow=true
        bOwnerNoSee=false
        LightEnvironment=MyLightEnvironment;
		BlockRigidBody=true;
		CollideActors=true;
		BlockZeroExtent=true;
//What to change if you'd like to use your own meshes and animations
        PhysicsAsset=PhysicsAsset'BD_CHARACTERS.Mesh.Vincent_Physics'
        AnimSets(0)=AnimSet'BD_CHARACTERS.Animation.Vincent_MoveSet'
        AnimSets(1)=AnimSet'BD_CHARACTERS.Animation.VincentMoveSet'
        AnimTreeTemplate=AnimTree'BD_CHARACTERS.Animation.Human_AnimTree'
        SkeletalMesh=SkeletalMesh'BD_CHARACTERS.Mesh.Vincent'
    End Object
//Setting up a proper collision cylinder
    Mesh=InitialSkeletalMesh;
    Components.Add(InitialSkeletalMesh); 
	CollisionType=COLLIDE_BlockAll
	Begin Object Name=CollisionCylinder
		CollisionRadius=+0024.000000
		CollisionHeight=+0044.000000
	End Object
	CylinderComponent=CollisionCylinder
	
	//Temp fix, creat fire effects here and apply when neccisary
	Begin Object Class=ParticleSystemComponent Name=FireEffect
		bAutoActivate=TRUE
		Template=ParticleSystem'BD_FX.ParticleSystems.Fire'
		Scale3D=(X=3.0,Y=3.00,Z=3.00)
		//Translation=(X=0.0,Y=0.0,Z=-44.0)
		SecondsBeforeInactive=1.0f
	End Object
	FireParticleEffectComponent=FireEffect
	
	HealthMax = 100
	FireDamage = 5;
	
	AirSpeed=150.000000
	GroundSpeed=150.000000
	bCanCrouch=False
	bCanClimbLadders=False
	bCanPickupInventory=False
	bCanBeDamaged=true
	bCanSwim=true
	
	jumpz = 250;
	
	WeaponSocket=WeaponPoint
	fireSocket=FireEffectSocket
}
